﻿using System;
using System.Collections.Generic;
using System.Collections;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace FileHandling
{
    public partial class Form1 : Form
    {
       
        public record yeni;
        public int counter = MySettings.TotalRecord;
        public Form1()
        {
            InitializeComponent();
            
        }

        private void button1_Click(object sender, EventArgs e)
        {
            
            textBox4.Text = counter.ToString();
            yeni.recordnumber = MySettings.TotalRecord + 1;
            yeni.isdeleted = "0xFF";
            yeni.ad = textBox1.Text;
            yeni.soyad = textBox2.Text;
            yeni.yas = int.Parse(textBox3.Text);
            MySettings.Save(yeni);
            counter = MySettings.TotalRecord;
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
            textBox4.Text = counter.ToString();


        }

        private void Form1_Load(object sender, EventArgs e)
        {
            textBox4.Text = counter.ToString();
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            int kayitNo = int.Parse(textBox4.Text);
            bool isDeleted = MySettings.deleteRecord(kayitNo);
            if (isDeleted)
                MessageBox.Show("Kayit Basariyla Silindi...");
            else
                MessageBox.Show("Kayit Silinemedi...");
        }

        private void button5_Click(object sender, EventArgs e)
        {
            string[] kayit;
            int kayitno = int.Parse(textBox4.Text);
            kayit = MySettings.Load(kayitno);
            if (kayit == null) 
            {
                MessageBox.Show("Aranilan kayit bulunamadi..");
                return;
            }
            textBox4.Text = kayit[0].ToString();
            textBox1.Text = kayit[2];
            textBox2.Text = kayit[3];
            textBox3.Text = kayit[4].ToString();

            //MessageBox.Show(kayit.recordnumber.ToString());
            //MessageBox.Show(kayit.isdeleted.ToString());
            //MessageBox.Show(kayit.ad.ToString());
            //MessageBox.Show(kayit.soyad.ToString());
            //MessageBox.Show(kayit.yas.ToString());
        }
    }
}
